package com.dubbo.regulate.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.dubbo.regulate.entity.UserEntity;
import com.dubbo.regulate.mapper.UserMapper;
import com.dubbo.service.UserService;
import com.dubbo.vo.BaseResp;
import com.dubbo.vo.UserListVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

//dubbo注解，暴露服务
@Service
@Component
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public BaseResp<UserListVo> findAll() {
        BaseResp<UserListVo> resp = new BaseResp<>();
        UserListVo listVo = new UserListVo();
        List<UserEntity> userList = userMapper.findAll();
         userList.stream().forEach(e -> {
            UserListVo.UserVo vo = new UserListVo.UserVo();
            BeanUtils.copyProperties(e, vo);
            listVo.getList().add(vo);
        });
        listVo.setCount(userMapper.count(new UserEntity()));
        resp.setInfo(listVo);
        return resp;
    }
}
